package com.ruoyi.womp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.womp.domain.WompWeighingApparatusType;
import com.ruoyi.womp.service.IWompWeighingApparatusTypeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 衡器类型列表Controller
 * 
 * @author mzz
 * @date 2022-04-14
 */
@Controller
@RequestMapping("/womp/waType")
public class WompWeighingApparatusTypeController extends BaseController
{
    private String prefix = "womp/waType";

    @Autowired
    private IWompWeighingApparatusTypeService wompWeighingApparatusTypeService;

    @RequiresPermissions("womp:waType:view")
    @GetMapping()
    public String waType()
    {
        return prefix + "/waType";
    }

    /**
     * 查询衡器类型列表列表
     */
    @RequiresPermissions("womp:waType:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WompWeighingApparatusType wompWeighingApparatusType)
    {
        startPage();
        List<WompWeighingApparatusType> list = wompWeighingApparatusTypeService.selectWompWeighingApparatusTypeList(wompWeighingApparatusType);
        return getDataTable(list);
    }

    /**
     * 导出衡器类型列表列表
     */
    @RequiresPermissions("womp:waType:export")
    @Log(title = "衡器类型列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WompWeighingApparatusType wompWeighingApparatusType)
    {
        List<WompWeighingApparatusType> list = wompWeighingApparatusTypeService.selectWompWeighingApparatusTypeList(wompWeighingApparatusType);
        ExcelUtil<WompWeighingApparatusType> util = new ExcelUtil<WompWeighingApparatusType>(WompWeighingApparatusType.class);
        return util.exportExcel(list, "衡器类型列表数据");
    }

    /**
     * 新增衡器类型列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存衡器类型列表
     */
    @RequiresPermissions("womp:waType:add")
    @Log(title = "衡器类型列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WompWeighingApparatusType wompWeighingApparatusType)
    {
        return toAjax(wompWeighingApparatusTypeService.insertWompWeighingApparatusType(wompWeighingApparatusType));
    }

    /**
     * 修改衡器类型列表
     */
    @RequiresPermissions("womp:waType:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        WompWeighingApparatusType wompWeighingApparatusType = wompWeighingApparatusTypeService.selectWompWeighingApparatusTypeById(id);
        mmap.put("wompWeighingApparatusType", wompWeighingApparatusType);
        return prefix + "/edit";
    }

    /**
     * 修改保存衡器类型列表
     */
    @RequiresPermissions("womp:waType:edit")
    @Log(title = "衡器类型列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WompWeighingApparatusType wompWeighingApparatusType)
    {
        return toAjax(wompWeighingApparatusTypeService.updateWompWeighingApparatusType(wompWeighingApparatusType));
    }

    /**
     * 删除衡器类型列表
     */
    @RequiresPermissions("womp:waType:remove")
    @Log(title = "衡器类型列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wompWeighingApparatusTypeService.deleteWompWeighingApparatusTypeByIds(ids));
    }
}
